package com.lingkang.flychat;

import android.app.Application;

import com.lingkang.flychat.mapper.gen.DaoMaster;
import com.lingkang.flychat.mapper.gen.DaoSession;
import com.orhanobut.hawk.Hawk;

import org.greenrobot.greendao.database.Database;


public class FlyChatApplication extends Application {

    public DaoSession daoSession;

    @Override
    public void onCreate() {
        super.onCreate();
        initSQLite();
        initUI();
        initLogin();
    }

    private void initLogin() {
        Hawk.put("isLogin", false);
    }

    private void initSQLite() {
        // regular SQLite database   其中 fcdb为数据库名称
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "fcdb");
        Database db = helper.getWritableDb();
        // 如果想要加密就使用以下：encryption-key是你想要的key
        //Database db = helper.getEncryptedWritableDb("encryption-key");
        daoSession = new DaoMaster(db).newSession();
    }

    public DaoSession getDaoSession() {
        return daoSession;
    }

    private void initUI() {
        //初始化
        Hawk.init(this).build();
    }
}
